<?php
include_once("../configure/admin.config.inc.php");	//--> admin global var
include_once("db.inc.php");							//--> db global var
include_once("Smarty.class.php");					//--> out template
include_once("Operation.php");						//--> Operation class
include_once("Access.php");							//--> Access class
include_once("Validation.php");						//--> validation
require_once("controlHeader.php");					//--> system control header

$objOperate	= new Operation($objSession->getLanguage());	//--> Operation instance
$objAccess 	= new Access($objSession->getLanguage());		//--> Access instance
$objValidation 	= new Validation();							//--> Validation

$selfFileName = '';
$error_message 		= '';
$strMenuGroupName 	= '';
$where 		= '';
$keyword 	= '';
$searchType = '';

if(isset($_GET['keyword']) && (!empty($_GET['keyword']) || $_GET['keyword'] == '0')){
	$searchType = $_GET['searchType'];
	$keyword 	= $_GET['keyword'];
		
	if($searchType == "ip")
		$where 	= " WHERE ip='$keyword'";
	else if($searchType == "date")
		$where 	= " WHERE visitDate='$keyword' ORDER BY visitDate DESC";
	else if($searchType == "classid"){
		if($objValidation->isNumber($keyword)){
			$where 	= " WHERE classid=$keyword ORDER BY visitDate DESC";
		}else
			$error_message = 'Keyword isn\'t number.';
	}
}else{
	$where = ' ORDER BY visitDate DESC';
}

$arrOperate = $objOperate->arrGetFromGroupIDAndMenuID($gid, $menuid);
if(count($arrOperate) > 0){
	$strQuery = $_SERVER["REQUEST_URI"];
	$arrUrlInfo 	= pathinfo($strQuery);
	$selfFileName	= $arrUrlInfo['filename'];
	
	$arrOperateAllInfo = $objOperate->listFromCustom($arrOperate, " WHERE id in (".implode(",", $arrOperate).")");
	
	
	$i = 0; 
	foreach($arrOperateAllInfo as $key => $value){
		$strFileName = $selfFileName."_".$value['name'].".php";

		if(file_exists($strFileName)){
			$arrOperateInfo[$i]['name'] 		= $value['name'];
			$arrOperateInfo[$i]['viewName'] 	= $value['viewName'];
			
			$i++;
		}
	}
}

$arrDataList = $objAccess->lists($arrOperate, DB_TAG_SYSTEM, $where, $page, DISPLAY_DATA_SIZE, '');
foreach($arrDataList as $key => $value){

}

$arrSearchType = array("ip" => "IP", "pageid" => "Page", "date" => "Date");

/*----- out html -----*/
$smarty = new Smarty();					//----- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;

$smarty->assign('error_message', $error_message);
$smarty->assign('menuGid', $menuGid);
$smarty->assign('menuid', $menuid);

$smarty->assign('searchTypeS', $searchType);
$smarty->assign('arrSearchType', $arrSearchType);

$smarty->assign('selfFileName', $selfFileName);
$smarty->assign('arrOperateInfo', $arrOperateInfo);

$smarty->assign('arrDataList', $arrDataList);
$smarty->assign('keyword', $keyword);
$smarty->assign('PAGE_BAR', $objAccess->pagenav);

$smarty->display('listAccessLog.htm');
?>
